<template>
  <div class="cashboxUninstall">
    <basic-container>
      <avue-crud
        ref="crud"
        :option="option"
        :table-loading="listLoading"
        :data="list"
	:permission="permissionList"
        :page.sync="page"
        @refresh-change="refreshChange"
        @search-change="handleFilter"
        @selection-change="selectionChange"
        @on-load="getList">
        <template slot="searchMenu" slot-scope="{row,size}">
          <el-button :size="size" @click="()=>{setSearchFiledsEmpty(row);setSearchFiledsEmpty(searchForm);getList()}" icon="el-icon-delete">清空</el-button>
        </template>
        <template slot-scope="scope" slot="menuRight">
          <el-button type="primary"  size="mini" v-permission="false" @click="openRuZhangDate()">设置入账日期</el-button>
	  <el-button type="primary" size="mini"  v-permission="permissionList.highDelData" @click="highDelData()">高级删除</el-button>
          <el-button type="primary"  size="mini" @click="exportData">导出</el-button>
	 
        </template>
      </avue-crud>
      <el-dialog
        title="设置入账日期"
        :visible.sync="dialogVisible"
        width="30%"
       >
        <span>设置入账日期：</span><el-date-picker
            v-model="param.postDate"
            type="date"
            value-format="yyyy-MM-dd"
            :picker-options="{disabledDate(time){return time.getTime() > Date.now();}}"
            placeholder="选择日期">
          </el-date-picker>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="setRuZhangDate()">确 定</el-button>
        </span>
      </el-dialog>
    </basic-container>
  </div>

</template>

<script>
  import {getForm, postForm} from '@/api/gen/gen'
  import moment from 'moment';
  import {mapGetters} from 'vuex';
  import {setSearchFiledsEmpty} from "../../../api/subwayRat/commonCheck";
  import {
    tableOption,
    getCashboxUninstallList,
    highDelCashBox,
    setCashboxUninstallPostDate
  } from '../../../api/subwayRat/TVMRevenueVarianceAudit.TvmChaYiDXC/CheZhanQianXiangNotUnstallSH';
  import {exportDataToExcel} from "../../../api/subwayRat/exportSelf";
  export default {
    name: 'cashboxUninstall',
    components:{
      moment
    },
    data() {
      return {
        param:{postDate:''},
        dialogVisible:false,
        option: tableOption,
        listLoading: true,
        selectKeys:[],
        selectKeyVals:[],	
        searchForm:{
          lineCode:'',
          stationCode:''
        },
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 20, // 每页显示多少条,
          isAsc: false// 是否倒序
        },
        list : []
      }
    },
    computed: {
          ...mapGetters(['permissions']),
          permissionList () {
            return {
              highDelData: this.vaildData(
                this.permissions.sw_st_input_cashbox_uninstalled_highdel,
                false
              ),
            };
          }
        },
    watch: {
    },
    created() {
    },
    methods: {
      setSearchFiledsEmpty,
      refreshChange() {
        this.getList()
      },
      getList() {
        this.selectKeys=[];
        this.selectKeyVals=[];		
        this.listLoading = true;
        this.page.size = this.page.pageSize;
        this.page.current = this.page.currentPage;
        Object.assign(this.searchForm,this.page);
        getCashboxUninstallList(this.searchForm).then((response)=>{
          // this.list = response.data.data;
          // this.page.total=response.data.total;
          this.list =response.data.data.records;
          this.listLoading = false;
          this.page.total=response.data.data.total;
        });
      },
      selectionChange(list){    
        this.selectKeys=list;
        this.selectKeyVals=[];        
        for(let i=0;i<list.length;i++){
          this.selectKeyVals.push(list[i].id);
         }
      },
      handleFilter(params, done) {
        Object.assign(this.searchForm,params);
        this.getList()
        done()
      },
      openRuZhangDate(){
        if(this.selectKeys.length<=0){
          this.$message.warning("请至少选择一条数据！");
          return;
        }
        this.dialogVisible=true;
      },
      setRuZhangDate(){
        let p={};
        Object.assign(p,this.param);
        p.ids=this.selectKeyVals.join(",");

        setCashboxUninstallPostDate(p).then(res=>{
          if(res.data.code==0){
              this.$message.success("操作成功！");
              this.getList();
          }else {
            this.$message.error("操作失败！")
          }
        }).catch(e=>{
          this.$message.error("操作失败！")
        });
        this.dialogVisible=false;
      },
     //高级删除
      highDelData() {            
            if(this.selectKeyVals.length<=0){             
	      this.$message({
                message: '请选择操作项！',
                type: 'warning'
              });
              return;
            }
            this.$confirm('您是否要删除此数据？', '提示', {
              confirmButtonText: '是',
              cancelButtonText: '否',
              type: 'warning'
            }).then(() => {
              highDelCashBox({ids:this.selectKeyVals.join(","),delFlag:1}).then((res)=>{
                  this.$message({
                    message: res.data.code==0?'操作成功':'操作失败',
                    type: res.data.code==0?'success':'error',
                  });		
		  this.$refs.crud.selectClear();
                  this.getList(this.page);		 
                  done();
              });
            }).catch(() => {
            });
          },
     
      async exportData(){ // 导出
        let p={};
        Object.assign(p,this.searchForm);
        p.pageNo=1;
        p.pageSize=1000000000;
        p.size=1000000000;
        if(this.selectKeys.length>0){
          let newData = JSON.parse(JSON.stringify(this.selectKeys));
          exportDataToExcel(newData,tableOption.column,'钱箱未卸载审核');
        }else {
          let res=await getCashboxUninstallList(p);
          let data = res.data.data.records;
          exportDataToExcel(data,tableOption.column,'钱箱未卸载审核');
        }
      },
    }
  }
</script>
<style lang="scss">
  .cashboxUninstall {
    height: 100%;

    &__tree {
      padding-top: 3px;
      padding-right: 20px;
    }

    &__main {
      .el-card__body {
        padding-top: 0;
      }
    }
  }
</style>
